var ff = ff || {};
ff.form = {};

ff.form.load = function(element,data,callback)
{
 
   var obj = ff.com.getJqObj(element);
    var inputs = obj.find("input");
    inputs.each(function () {
 
            var name = $(this).attr("name");
	        if (null != name) {
               if(null == data)
               {
                 $(this).val("");  
               }
               else
               {
                  $(this).val(data[name]);
               }
	           
	        }
 
	    });
   if(null != callback)
   {
      callback(obj,data);
   }
};

ff.form.reset = function(element,callback)
{ 
    	var obj = ff.com.getJqObj(element);
    	obj[0].reset();
    	if(null != callback)
    	{
    	     callback(obj);
    	}
};

ff.form.view = function (element, data, callback)
{
	
    var obj = ff.com.getJqObj(element);
    var inputs = obj.find("span");
    inputs.each(function () {

        var name = $(this).attr("name");
        if (null != name) {
            if (null == data) {
                $(this).html("");
            }
            else {
                $(this).html(data[name]);
            }

        }

    });
    if (null != callback) {
        callback(obj, data);
    }
}


ff.form.banner = function (element, data,callback) {
    
    var obj = ff.com.getJqObj(element);
    var inputs = obj.find("span");
    var html = "";

    var onClickCall = function (swiper) {

        var clickUrl = data[data.length - 1];
        if (0 != swiper.clickedIndex) {
            clickUrl = data[swiper.clickedIndex - 1]
        }
        
        callback(clickUrl);
    }
    var mySwiper = new Swiper(element, {
        loop: true,
        pagination: '.swiper-pagination',
        onClick: onClickCall,
        autoplay: 3000
    })

    mySwiper.removeAllSlides();
    for (var i = 0; i < data.length; i++) {
        var url = data[i];
        //html += '<div class="swiper-slide">' + ' <img src="' + url + '" />' + '</div>';
        //var img = '<div class="swiper-slide">' + ' <img src="' + url + '" />' + '</div>';
         var img = '<div class="swiper-slide" style="background-image:url(\''+url+'\')"></div>'
        mySwiper.appendSlide(img);
    }

   // obj.html(html);

 
}

 
 
function clearDate()
{  
    var obj = $('.chooseDate label.active');
    if(null != obj)
    {
      obj.attr('class','btn btn-default btn-sm');
    }
};
function changeData(obj){
 	 var nowDate = new Date();
 	 var val = $(obj).attr('data-options');
 	 var prvDate =  new Date(nowDate.valueOf() -  val*24*60*60*1000);
 	 $('#ff_form_time_min_date').val(new Date(prvDate).format('yyyy-MM-dd')); 
	 $('#ff_form_time_max_date').val(new Date(nowDate.valueOf()-24*60*60*1000).format('yyyy-MM-dd'));
}
